package top.bigdata.model.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * api返回结果
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Response<T> {
    private int code; // 响应状态码
    private String message; // 响应消息
    private T data; // 响应数据

    public static <T> Response<T> success() {
        return new Response<>(200, "success", null);
    }

    public static <T> Response<T> success(String msg) {
        return new Response<>(200, msg, null);
    }

    public static <T> Response<T> success(T data) {
        return new Response<>(200, "success", data);
    }

    public static <T> Response<T> success(String msg, T data) {
        return new Response<>(200, msg, data);
    }

    public static <T> Response<T> success(int code) {
        return new Response<>(code, "success", null);
    }

    public static <T> Response<T> success(int code, T data) {
        return new Response<>(code, "success", data);
    }

    public static <T> Response<T> error() {
        return new Response<>(500, "error", null);
    }

    public static <T> Response<T> error(String msg) {
        return new Response<>(500, msg, null);
    }

    public static <T> Response<T> error(T data) {
        return new Response<>(500, "error", data);
    }

    public static <T> Response<T> error(String msg, T data) {
        return new Response<>(500, msg, data);
    }

    public static <T> Response<T> error(int code) {
        return new Response<>(code, "error", null);
    }

    public static <T> Response<T> error(int code, T data) {
        return new Response<>(code, "error", data);
    }
}
